# -*- coding: UTF-8 -*-

from google.appengine.ext import db
from appengine_django.models import BaseModel
from google.appengine.ext.db import djangoforms


class Greeting(BaseModel):
    """ 留言信息 """
    
    # 留言用户可能是google用户（type：google），
    # 也可能是其它用户，这时候就需要他们输入自己的名字、url、mail等信息了
    author_type = db.CategoryProperty()     # 留言者类别（google or other）
    google_author = db.UserProperty()       # 留言者类别为google时记录在此
    author_name = db.StringProperty()
    author_url = db.StringProperty()
    author_mail = db.EmailProperty()
    
    content = db.TextProperty() # 留言内容
    parent_greeting = db.SelfReferenceProperty()    # 自关联
    
    create_time = db.DateTimeProperty(auto_now_add = True) # 创建时间
    update_time = db.DateTimeProperty(auto_now_add = True, auto_now = True) # 修改时间
    
    def __greetingStr(self):
        return "%s, %s, %s" % (self.google_author, self.author_name, self.content)
    
    def __unicode__(self):
        return unicode(self.__greetingStr())
    
    def __str__(self):
        return (self.__greetingStr())


class GreetingForm(djangoforms.ModelForm):
    class Meta:
        model = Greeting
        exclude = ['google_author', 'parent_greeting', 'create_time', 'update_time']